﻿Imports Microsoft.TeamFoundation.VersionControl.Client

Public Class TFSSourceFileSelector

    Private vcs As VersionControlServer

    Public Shared Function SelectFile(vcs As VersionControlServer, ByRef filename As String) As Boolean
        Dim frm As New TFSSourceFileSelector(vcs)
        Dim result As DialogResult = frm.ShowDialog
        If result = Windows.Forms.DialogResult.Cancel Then Return False
        filename = frm.TreeView1.SelectedNode.Text
        Return True
    End Function

    Public Sub New(vcs As VersionControlServer)
        Me.InitializeComponent()
        Me.vcs = vcs
    End Sub

    Private Sub TFSSourceFileSelector_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim node As TreeNode = TreeView1.Nodes.Add("$/", "$/")
        node.Nodes.Add("$/abc", "abc")
    End Sub


    Private Sub TreeView1_BeforeExpand(sender As System.Object, e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand
        If e.Node.Nodes.Count = 1 AndAlso e.Node.Nodes(0).Text = "abc" Then
            e.Node.Nodes.Clear()

            Dim tl As TreeView = sender
            Dim subItems As ItemSet = vcs.GetItems(e.Node.Text + "/", RecursionType.OneLevel)
            For Each i As Item In subItems.Items
                If i.ServerItem = e.Node.Text Then
                    Continue For
                End If
                Dim node As TreeNode = e.Node.Nodes.Add(i.ServerItem, i.ServerItem)
                node.Nodes.Add("$/abc", "abc")
            Next
        End If
    End Sub

    Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
        Me.DialogResult = DialogResult.OK
    End Sub
End Class